import { Exclude, Expose } from 'class-transformer';
import {
  BeforeInsert,
  CreateDateColumn,
  PrimaryColumn,
  BaseEntity as TypeormBaseEntity,
  UpdateDateColumn,
} from 'typeorm';
import { v4 as uuidv4 } from 'uuid';
export class BaseEntity extends TypeormBaseEntity {
  @Expose()
  @PrimaryColumn({ type: 'varchar', generated: 'uuid', length: 36 })
  id: string;

  @BeforeInsert()
  generateId() {
    this.id = uuidv4().replace(/-/g, '');
  }

  @Exclude()
  @CreateDateColumn({
    comment: '创建时间',
  })
  createdAt: Date;

  @Exclude()
  @UpdateDateColumn({
    comment: '更新时间',
  })
  updatedAt: Date;
}
